#include <at89c51RC2.h>
#include <LCD1602.h>
#include <Key.h>
#include <AT24C02.h>
#include <Delay.h>

unsigned char KeyNum;
unsigned int Num;


void main()
{
	LCD_Init();
	LCD_ShowNum(1,1,Num,5);
	while(1)
	{
		KeyNum=Key();
		if(KeyNum==1)
		{
			Num++;
			LCD_ShowNum(1,1,Num,5);
		}
		if(KeyNum==2)
		{
			Num--;
			LCD_ShowNum(1,1,Num,5);
		}
		if(KeyNum==3)
		{
			AT24C02_WriteByte(0,Num%256);  //取出Num的低八位
			Delay(5);
			AT24C02_WriteByte(1,Num/256);  //取出Num的高八位
			Delay(5);
			LCD_ShowString(2,1,"Write success!");
			Delay(1000);
			LCD_ShowString(2,1,"              ");
		}
		if(KeyNum==4)
		{
			Num=AT24C02_ReadByte(0);        //获取低八位
			Num|=AT24C02_ReadByte(1)<<8;    //获取高八位
			LCD_ShowNum(1,1,Num,5);
			LCD_ShowString(2,1,"Read success!");
			Delay(1000);
			LCD_ShowString(2,1,"              ");
		}
	}
}